package com.tools.developer.util;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.media.AudioManager;
import android.preference.PreferenceManager;
import android.text.TextUtils;

import com.tools.developer.common.ToolsDeveloper;

/**
 * 偏好设置
 */
public class SharedPrefHelper {
	private static final String AD_SHOW_BANNER_ = "ad_show_banner";
	private static final String AD_SHOW_SCREEN = "ad_show_screen";
	private static final String FIRST_INSTALL_TIME = "first_install_time";
	private static final String SCREEN_BRIGHTNESS_MODE = "screen_brightness_mode_";
	private static final String SCREEN_BRIGHTNESS = "screen_brightness_";
	private static final String SCREEN_OFF_TIMEOUT = "screen_off_timeout_";
	private static final String WIFI_SETTING = "wifi_setting_";
	private static final String BLUETOOTH_SETTING = "bluetooth_setting_";
	private static final String MASTER_SYNC_AUTO_MATICALLY = "master_sync_auto_matically_";
	private static final String VIBRATE_MODE = "vibrate_mode_";
	private static final String FEED_BACK = "feed_back_";
	private static final String MOBILE_DATA = "mobile_data_";
	private static final String SILENT_MODE = "silent_mode_";
	private static final String BATTERY_LEVEL = "battery_level";
	private static final String BATTERY_STATUS = "battery_status";
	private static final String BATTERY_ELAPSE = "battery_elapse";
	private static final String BATTERY_NEXT_PHASE = "battery_next_phase";
	private static final String AFTER_FULL_TIME_LENGTH = "after_full_time_length";
	private static final String PREFERENCES_AUTO_STARTUP = "preferences_auto_startup";
	private static final String PREFERENCES_AUTO_SAVER = "preferences_auto_saver";
	private static final String PREFERENCES_AUTO_UPDATE = "preferences_auto_update";

	// 摇一摇设置
	private static final String PREFERENCES_SHAKE_SHAKE = "preferences_shake_shake";
	private static final String PREFERENCES_SHAKE_SHAKE_VALUE = "preferences_shake_config_new";

	private static final String NOTIFICATIONBAR_SHOW_BATTERY_ICON = "notificationbar_show_battery_icon";
	private static final String CHANGING_DONE_NOTIFICATION = "changing_done_notification";
	private static final String CHANGING_NOTIFICATION = "changing_notification";
	private static final String CHANGING_LOCKSCREEN = "changing_lockscreen";
	private static final boolean CHANGING_LOCKSCREEN_DEFAULT_STATUS_FALSE = false;
	private static final boolean CHANGING_LOCKSCREEN_DEFAULT_STATUS_TRUE = true;
	private static final int CHANGING_LOCKSCREEN_VERCODE = 2000296;

	// 低电量提醒设置
	private static final String LOW_BATTERY_NOTIFICATION = "low_battery_notification";
	private static final String LOW_BATTERY_NOTIFICATION_VALUE = "low_battery_notification_list";

	private static final String CUSTOM_USER_MODE_LIST = "custom_user_mode_list";
	private static final String CUSTOM_USER_MODE_SELECTED_INDEX = "custom_user_mode_selected_index";
	private static final String COMPLETE_CIRCLE_CHARGING_INTERVAL = "complete_circle_charging_interval";
	private static final String OPTIMIZATION_INTERVAL = "optimization_interval";
	private static final String MEM_CLEAN_TIME = "mem_clean_time";
	private static final String MEM_CLEAN_PROCESS_COUNT = "mem_clean_process_count";
	private static final String LOW_MODE_SWITCH = "low_mode_switch";
	private static final String LOW_MODE_LEVEL = "low_mode_level";
	private static final String LOW_MODE_POSITION = "low_mode_position";
	private static final String TEMP_LOW_MODE_POSITION = "temp_low_mode_position";
	private static final String TEMP_SLEEP_MODE_POSITION = "temp_sleep_mode_position";
	private static final String TEMP_SLEEP_MODE_NAME = "temp_sleep_mode_name";
	private static final String SLEEP_MODE_SWITCH = "sleep_mode_switch";
	private static final String SLEEP_MODE_START_TIME = "sleep_mode_start_time";
	private static final String SLEEP_MODE_END_TIME = "sleep_mode_end_time";
	private static final String SLEEP_MODE_POSITION = "sleep_mode_position";
	private static final String SLEEP_MODE_NAME = "sleep_mode_name";
	private static final String ISOPEN_LOW_MODE = "isopen_low_mode";
	private static final String BATTERY_AVAILABLE_TIME = "battery_available_time";
	private static final String PHONE_LOW_MODE_SWITCH = "phone_low_mode_switch";
	private static final String SCREEN_TIMEOUT_INTEL_MODE_SWITCH = "screen_timeout_intel_mode_switch";
	private static final String SCREEN_TIMEOUT_INTEL_START_TIME = "screen_timeout_intel_start_time";
	private static final String WIFI_INTEL_MODE_SWITCH = "wifi_intel_mode_switch";
	private static final String BLUETOOTH_INTEL_MODE_SWITCH = "bluetooth_intel_mode_switch";
	private static final String ROOT_INTEL_MODE_SWITCH = "root_intel_mode_switch";
	private static final String ROOT_REPORTED = "root_reported";
	private static final String SET_ON_BOOT = "set_on_boot";
	private static final String CPU_SELECT_FREQ_MIN = "cpu_selected_minfreq";
	private static final String CPU_SELECT_FREQ_MAX = "cpu_selected_maxfreq";
	private static final String CPU_SELECT_GOVERNOR = "cpu_selected_governor";
	private static final String CUR_SCALING_FREQ_MIN = "cur_scaling_freq_min";
	private static final String CUR_SCALING_FREQ_MAX = "cur_scaling_freq_max";
	private static final String CPU_SCREEN_FREQ_MIN = "cpu_screen_freq_min";
	private static final String CPU_SCREEN_FREQ_MAX = "cpu_screen_freq_max";
	private static final String CUR_SCALING_GOVERNOR = "cur_scaling_governor";
	private static final String CPU_SCREEN_START_TIME = "cpu_screen_start_time";
	private static final String CPU_SCREEN_END_TIME = "cpu_screen_end_time";
	private static final String SCREEN_CPU_STATUS = "screen_cpu_status";
	private static final String SCREEN_CPU_TYPE = "screen_cpu_type";
	private static final String SCREEN_GOVERNOR_TYPE = "screen_governor_type";
	private static final String SCREEN_TIME_CALCULATED = "screen_time_calculated";
	private static final String PHONE_SINGAL_STATE_SWITCH = "phone_singal_state_switch";
	private static final String BLUETOOTH_MONITOR_START_TIME = "bluetooth_monitor_start_time";
	private static final String WIFI_MONITOR_START_TIME = "wifi_monitor_start_time";
	private static final String MM_MONITOR_START_TIME = "mm_monitor_start_time";
	private static final String PHONE_SINGAL_HIGH_START_TIME = "phone_singal_high_start_time";
	private static final String PHONE_SINGAL_LOW_START_TIME = "phone_singal_low_start_time";
	private static final String BATTERY_REMAIN_LENGTH = "battery_remain_length";
	private static final String UPLOAD_BATTERYLEVEL = "upload_batterylevel";
	private static final String LAST_BUG_FEED_TIME = "LastBugFeedTime";
	private static final String REPORT_ACTIVE_TIME = "report_active_time";
	private static final String WIFI_NOTICE_TIME = "wifi_notice_time";
	private static final String MM_NOTICE_TIME = "mm_notice_time";
	private static final String LAST_BUG_FEED_COUNT = "LastBugFeedCount";
	private static final String SERVICE_STARTUP_VERSION = "ServiceStartupVersion";
	private static final String SCREEN_LOCK_MEMORY_CLEAN = "screen_lock_memory_clean";
	private static final String MEMORY_CLEAN_WHITE_LIST = "memory_clean_white_list";
	private static final String SHORTCUT_ITEM_LIST = "SHORTCUT_ITEM_LIST";
	private static final String LOG_DETAIL = "log_detail";
	private static final String KBD_UUID = "kbd_uuid";
	private static final String CURRENT_PHONE_STATE = "current_phone_state";
	private static final String SWITCH_OFF_LINE = "switch_off_line";
	private static final String SHOW_PLUG_NOTIFY = "SHOW_PLUG_NOTIFY";
	// 程序退出标志位--menu中的“退出”
	private static final String EXIT_FLAG = "exit_flag";

	private static final String SCREEN_WIDTH = "screen_width";
	private static final String SCREEN_HEIGTH = "screen_heigth";
	private static final String SCREEN_DENSITY = "screen_density";

	private static final String PLUGGED_STATUS = "plugged_status";

	// 金山省电开关快捷方式
	private static final String SHORTCUTINSTALLED = "shortcut_installed";

	// 金山省电快捷方式
	private static final String BATTERY_SHORTCUTINSTALLED = "battery_shortcut_installed";
	// 开关改版后需要新的key
	private static final String BATTERY_SHORTCUT_NEW_INSTALLED = "battery_shortcut_new_installed";

	// 省电优化快捷方式
	private static final String BATTERY_ONKEY_SHORTCUT_INSTALLED = "BATTERY_ONKEY_SHORTCUT_INSTALLED";

	// 初始化白名单一次， 新安装和覆盖安装都可以
	private static final String INIT_WHITE_APP_LIST = "init_white_app_list";

	// MARK：屏保配置
	private static final String SCR_COLORFUL_COLOR = "scr_colorful_color";
	private static final String SCR_COLORFUL_BRIGHTNESS = "scr_colorful_brightness";

	private static SharedPrefHelper configManager;

	private final SharedPreferences mSharedPreferences;

	private final SharedPreferences mSharedPreferences2Apps;

	// 充电预估时间
	private static final String ANALYSIS_CHARGE_ESTIMATE = "analysis_charge_estimate";

	// 状态栏图标样式
	private static final String STATUS_ICON_STYLE = "status_icon_style";

	// 小部件背景样式
	private static final String WIDGET_BG_STYLE = "widget_bg_style";

	public static final String CLOCK_REPEAT = "clock_repeat";

	private static final String SCORE = "score";
	private static final String SCORE_BASE = "score_base";
	private static final String SCORE_DATE = "score_date";
	private static final String SCORE_DAY = "score_day";
	private static final String SCORE_TIP = "SCORE_TIP";
	public static final int SCORE_TIP_NOR = 0;
	public static final int SCORE_TIP_OVER = 1;
	public static final int SCORE_TIP_FULL = 2;
	public static final int SCORE_TIP_FULL_MORE = 3;
	public static final int SCORE_TIP_M_DAYS = 4;
	/**
	 * 标记后台数据是否改变
	 */
	private static final String PREFERENCE_HTTP_ETAG = "preference_http_etag";
	private static final String PREFERENCE_NEW_APPS = "preference_new_apps";
	public static final String LOW_LEVEL_CHANGE_ID = "low_level_change_id";

	private static final String SHOW_GPRS_TIPS_TIME = "show_gprs_tips_time";
	private static final String FIRST_INSTALL = "isFirstInstall";
	private static final String VERSION_CODE = "v_id";

	private SharedPrefHelper(Context context) {
		mSharedPreferences = PreferenceManager
				.getDefaultSharedPreferences(context);
		mSharedPreferences
				.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() {
					@Override
					public void onSharedPreferenceChanged(
							SharedPreferences sharedPreferences, String key) {
					}
				});
		mSharedPreferences2Apps = context.getApplicationContext()
				.getSharedPreferences(Constant.DOWNLOAD_APPS,
						Context.MODE_PRIVATE);
	}

	public static synchronized SharedPrefHelper getInstanse(Context context) {
		if (configManager == null) {
			configManager = new SharedPrefHelper(context);
		}
		return configManager;

	}

	public long getFirstInstallTime(long value) {
		return mSharedPreferences.getLong(FIRST_INSTALL_TIME, value);
	}

	public void setFirstInstallTime(long time) {
		Editor editor = mSharedPreferences.edit();
		editor.putLong(FIRST_INSTALL_TIME, time);
		editor.commit();
	}

	public long getLastBugFeedTime() {
		return mSharedPreferences.getLong(LAST_BUG_FEED_TIME, 0);
	}

	public void setLastBugFeedTime(long time) {
		Editor editor = mSharedPreferences.edit();
		editor.putLong(LAST_BUG_FEED_TIME, time);
		editor.commit();
	}

	public long getReportTime() {
		return mSharedPreferences.getLong(REPORT_ACTIVE_TIME, 0);
	}

	public void setReportTime(long time) {
		Editor editor = mSharedPreferences.edit();
		editor.putLong(REPORT_ACTIVE_TIME, time);
		editor.commit();
	}

	public void setWifiNoticeTime(long time) {
		Editor editor = mSharedPreferences.edit();
		editor.putLong(WIFI_NOTICE_TIME, time);
		editor.commit();
	}

	public long getWifiNoticeTime() {
		return mSharedPreferences.getLong(WIFI_NOTICE_TIME, 0);
	}

	public void setMmNoticeTime(long time) {
		Editor editor = mSharedPreferences.edit();
		editor.putLong(MM_NOTICE_TIME, time);
		editor.commit();
	}

	public long getMmNoticeTime() {
		return mSharedPreferences.getLong(MM_NOTICE_TIME, 0);
	}

	public int getLastBugFeedCount() {
		return mSharedPreferences.getInt(LAST_BUG_FEED_COUNT, 0);
	}

	public void setLastBugFeedCount(int count) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(LAST_BUG_FEED_COUNT, count);
		editor.commit();
	}

	public void setServiceStartupVersion(Context context) {
		Editor editor = mSharedPreferences.edit();
		editor.putString(SERVICE_STARTUP_VERSION, Env.getVersionName(context));
		editor.commit();
	}

	public String getServiceStartupVersion(String defaultStr) {
		return mSharedPreferences
				.getString(SERVICE_STARTUP_VERSION, defaultStr);
	}

	public void setKbdUUID(String defaultStr) {
		Editor editor = mSharedPreferences.edit();
		editor.putString(KBD_UUID, defaultStr);
		editor.commit();
	}

	public String getKbdUUID() {
		String uuid = mSharedPreferences
				.getString(KBD_UUID, Constant.STR_BLANK);
		if (TextUtils.isEmpty(uuid)) {
			uuid = UUID.randomUUID().toString().replaceAll("-", "");
			setKbdUUID(uuid);
		}
		return uuid;
	}

	public void setLogDetail(String value) {
		Editor editor = mSharedPreferences.edit();
		editor.putString(LOG_DETAIL, value);
		editor.commit();
	}

	public String getLogDetail() {
		return mSharedPreferences.getString(LOG_DETAIL, "");
	}

	public void putShortcutList(String value) {
		Editor editor = mSharedPreferences.edit();
		editor.putString(SHORTCUT_ITEM_LIST, value);
		editor.commit();
	}

	public String getShortcutList(boolean flag) {
		if (flag) {
			return mSharedPreferences.getString(SHORTCUT_ITEM_LIST,
					Constant.DEFAULT_SHORTCUT_ORDER);
		} else {
			return mSharedPreferences.getString(SHORTCUT_ITEM_LIST,
					Constant.DEFAULT_SHORTCUT_NOBLUE_ORDER);
		}
	}

	public void putMemoryClean(boolean isOpen) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(SCREEN_LOCK_MEMORY_CLEAN, isOpen);
		editor.commit();
	}

	public boolean getMemoryClean(boolean isOpen) {
		return mSharedPreferences.getBoolean(SCREEN_LOCK_MEMORY_CLEAN, isOpen);
	}

	/**
	 * 保存白名单不要直接调用此处接口，有其他逻辑处理，统一调用processutil.java中的接口
	 * 
	 * @param value
	 */
	public void putWhiteList(String value) {
		Editor editor = mSharedPreferences.edit();
		editor.putString(MEMORY_CLEAN_WHITE_LIST, value);
		editor.commit();
	}

	public String getWhiteList() {
		return mSharedPreferences.getString(MEMORY_CLEAN_WHITE_LIST, "");
	}

	public void putWhiteListInited() {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(INIT_WHITE_APP_LIST, true);
		editor.commit();
	}

	public boolean getWhiteListInited() {
		return mSharedPreferences.getBoolean(INIT_WHITE_APP_LIST, false);
	}

	public boolean getUploadBatteryLevel() {
		return mSharedPreferences.getBoolean(UPLOAD_BATTERYLEVEL, true);
	}

	public void setUploadBatteryLevel() {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(UPLOAD_BATTERYLEVEL, false);
		editor.commit();
	}

	public String isNewer() {
		String b = mSharedPreferences.getString("isNewer", Constant.NEWER_1);
		if (Constant.NEWER_1.equals(b)) {
			Editor editor = mSharedPreferences.edit();
			editor.putString("isNewer", Constant.NEWER_0);
			editor.commit();
		}
		return b;
	}

	/**
	 * add the flag in 2.9.6
	 * 
	 * @return the first installed version code. return 0 when installed before
	 *         2.9.6
	 */
	public int getSavedVersionCode() {
		int verisonCode = 0;
		if (mSharedPreferences.getBoolean(FIRST_INSTALL, true)) {
			verisonCode = Env.getVersionCode(ToolsDeveloper.getInstance());
			saveVersionCode(verisonCode);
		} else {
			verisonCode = mSharedPreferences.getInt(VERSION_CODE, verisonCode);
		}
		return verisonCode;
	}

	public void saveVersionCode(int versionCode) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(VERSION_CODE, versionCode);
		editor.commit();
	}

	/**
	 * “推荐开启超级省电”对话框，仅首次安装显示一次
	 * 
	 * @return
	 */
	public boolean isFirstInstallDialog() {
		boolean value = mSharedPreferences.getBoolean("isFirstInstallDialog",
				true);
		if (value) {
			Editor editor = mSharedPreferences.edit();
			editor.putBoolean("isFirstInstallDialog", false);
			editor.commit();
		}
		return value;
	}

	public boolean isFirstInstall() {
		boolean b = mSharedPreferences.getBoolean(FIRST_INSTALL, true);
		if (b) {
			Editor editor = mSharedPreferences.edit();

			editor.putBoolean(FIRST_INSTALL, false);
			editor.commit();
			saveVersionCode(Env.getVersionCode(ToolsDeveloper.getInstance()));
		}

		return b;
	}

	public boolean isFirstInstall_Noti() {
		boolean b = mSharedPreferences.getBoolean("isFirstInstall_Noti", true);
		if (b) {
			Editor editor = mSharedPreferences.edit();

			editor.putBoolean("isFirstInstall_Noti", false);
			editor.commit();
		}

		return b;
	}

	// 1.4.1以后添加超级省电模式
	public boolean isFirstOverrideInstall() {
		boolean b = mSharedPreferences.getBoolean("isFirstOverrideInstall",
				true);
		if (b) {
			Editor editor = mSharedPreferences.edit();

			editor.putBoolean("isFirstOverrideInstall", false);
			editor.commit();
		}

		return b;
	}

	// 2.0正式版以后添加我的省电模式
	public boolean isSecondOverrideInstall() {
		boolean b = mSharedPreferences.getBoolean("isSecondOverrideInstall",
				true);
		if (b) {
			Editor editor = mSharedPreferences.edit();

			editor.putBoolean("isSecondOverrideInstall", false);
			editor.commit();
		}

		return b;
	}

	// 2.1正式版以后添加去掉普通、中级和我的省电模式
	public boolean isThirdOverrideInstall() {
		boolean b = mSharedPreferences.getBoolean("isThirdOverrideInstall",
				true);
		if (b) {
			Editor editor = mSharedPreferences.edit();

			editor.putBoolean("isThirdOverrideInstall", false);
			editor.commit();
		}

		return b;
	}

	// 2.7使用数据库存储模式信息
	public boolean isFifthOverrideInstall() {
		boolean b = mSharedPreferences.getBoolean("isFifthOverrideInstall",
				true);
		if (b) {
			Editor editor = mSharedPreferences.edit();

			editor.putBoolean("isFifthOverrideInstall", false);
			editor.commit();
		}

		return b;
	}

	// 2.2正式版以后添加3个固定的情景模式
	public boolean isForthOverrideInstall() {
		boolean b = mSharedPreferences.getBoolean("isForthOverrideInstall",
				true);
		if (b) {
			Editor editor = mSharedPreferences.edit();

			editor.putBoolean("isForthOverrideInstall", false);
			editor.commit();
		}

		return b;
	}

	// 2.0.3.1版本起，将前期版本的“内存清理”开关全部置为false,这个是设置的标志位
	public boolean isSetMemCleanFlase() {
		boolean b = mSharedPreferences.getBoolean(
				Constant.Preferences.MemClean_defValue, true);
		if (b) {
			Editor editor = mSharedPreferences.edit();
			editor.putBoolean(Constant.Preferences.MemClean_defValue, false);
			editor.commit();
		}
		return b;
	}

	public long getCircleInterval(long defaultValue) {
		return mSharedPreferences.getLong(COMPLETE_CIRCLE_CHARGING_INTERVAL,
				defaultValue);
	}

	public void putCircleInterval(long modeValue) {
		Editor editor = mSharedPreferences.edit();
		editor.putLong(COMPLETE_CIRCLE_CHARGING_INTERVAL, modeValue);
		editor.commit();
	}

	public boolean getAdScreenShow(boolean defValue, String id) {
		return mSharedPreferences.getBoolean(AD_SHOW_SCREEN + id, defValue);
	}

	// 设置某个id的广告是否显示
	public void putAdScreenShow(boolean value, String id) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(AD_SHOW_SCREEN + id, value);
		editor.commit();
	}

	public boolean getAdBannerShow(boolean defValue, String id) {
		return mSharedPreferences.getBoolean(AD_SHOW_BANNER_ + id, defValue);
	}

	// 设置某个id的广告是否显示
	public void putAdBannerShow(boolean value, String id) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(AD_SHOW_BANNER_ + id, value);
		editor.commit();
	}

	// public String getCurrentSavingMode(String defaultValue) {
	// return mSharedPreferences.getString(CURRENT_SAVING_MODE, defaultValue);
	// }

	// public void putCurrentSavingMode(String modeValue) {
	// Editor editor = mSharedPreferences.edit();
	// editor.putString(CURRENT_SAVING_MODE, modeValue);
	// editor.commit();
	// }

	public int getScreenBrightnessMode(int pos, int defaultValue) {
		return mSharedPreferences.getInt(SCREEN_BRIGHTNESS_MODE + pos,
				defaultValue);
	}

	public void putScreenBrightnessMode(int pos, int modeValue) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(SCREEN_BRIGHTNESS_MODE + pos, modeValue);
		editor.commit();
	}

	public void putScreenBrightness(int pos, int bright) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(SCREEN_BRIGHTNESS + pos, bright);
		editor.commit();
	}

	public int getScreenBrightness(int pos, int defaultValue) {
		return mSharedPreferences.getInt(SCREEN_BRIGHTNESS + pos, defaultValue);
	}

	public void putScreenOffTimeout(int pos, int offTime) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(SCREEN_OFF_TIMEOUT + pos, offTime);
		editor.commit();
	}

	public int getScreenOffTimeout(int pos, int defaultValue) {
		return mSharedPreferences
				.getInt(SCREEN_OFF_TIMEOUT + pos, defaultValue);
	}

	public void putWifiSettiing(int pos, int defaultValue) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(WIFI_SETTING + pos, defaultValue);
		editor.commit();
	}

	public int getWifiSettiing(int pos, int defaultValue) {
		return mSharedPreferences.getInt(WIFI_SETTING + pos, defaultValue);
	}

	public boolean getWifiSettiing(int pos, boolean defaultValue) {
		return mSharedPreferences.getBoolean(WIFI_SETTING + pos, defaultValue);
	}

	public void putBluetooth(int pos, boolean isOpen) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(BLUETOOTH_SETTING + pos, isOpen);
		editor.commit();
	}

	public boolean getBluetooth(int pos, boolean defaultValue) {
		return mSharedPreferences.getBoolean(BLUETOOTH_SETTING + pos,
				defaultValue);
	}

	public void putMasterSyncAutomatically(int pos, boolean isOpen) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(MASTER_SYNC_AUTO_MATICALLY + pos, isOpen);
		editor.commit();
	}

	public boolean getMasterSyncAutomatically(int pos, boolean defaultValue) {
		return mSharedPreferences.getBoolean(MASTER_SYNC_AUTO_MATICALLY + pos,
				defaultValue);
	}

	public void putIsOpenLowMode(boolean isOpen) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(ISOPEN_LOW_MODE, isOpen);
		editor.commit();
	}

	public boolean getIsOpenLowMode() {
		return mSharedPreferences.getBoolean(ISOPEN_LOW_MODE, true);
	}

	public void putVibrateMode(int pos, int modeValue) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(VIBRATE_MODE + pos, modeValue);
		editor.commit();
	}

	public boolean getVibrateMode(int pos) {
		return mSharedPreferences.getInt(VIBRATE_MODE + pos,
				AudioManager.VIBRATE_SETTING_OFF) == AudioManager.VIBRATE_SETTING_OFF ? false
				: true;
	}

	public void putFeedback(int pos, boolean isOpen) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(FEED_BACK + pos, isOpen);
		editor.commit();
	}

	public boolean getFeedback(int pos, boolean isOpen) {
		return mSharedPreferences.getBoolean(FEED_BACK + pos, isOpen);
	}

	public void putMobileData(int pos, boolean isOpen) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(MOBILE_DATA + pos, isOpen);
		editor.commit();
	}

	public boolean getMobileData(int pos, boolean isOpen) {
		return mSharedPreferences.getBoolean(MOBILE_DATA + pos, isOpen);
	}

	public void putSilentMode(int pos, boolean isOpen) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(SILENT_MODE + pos, isOpen);
		editor.commit();
	}

	public boolean getSilentMode(int pos, boolean isOpen) {
		return mSharedPreferences.getBoolean(SILENT_MODE + pos, isOpen);
	}

	public void putBatteryLevel(int level) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(BATTERY_LEVEL, level);
		editor.commit();
	}

	public int getBatteryLevel(int level) {
		return mSharedPreferences.getInt(BATTERY_LEVEL, level);
	}

	public void putBatteryStatus(int status) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(BATTERY_STATUS, status);
		editor.commit();
	}

	public int getBatteryStatus(int status) {
		return mSharedPreferences.getInt(BATTERY_STATUS, status);
	}

	public void putBatteryElapse(int length) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(BATTERY_ELAPSE, length);
		editor.commit();
	}

	public int getBatteryElapse(int length) {
		return mSharedPreferences.getInt(BATTERY_ELAPSE, length);
	}

	public void putBatteryNextPhase(long length) {
		Editor editor = mSharedPreferences.edit();
		editor.putLong(BATTERY_NEXT_PHASE, length);
		editor.commit();
	}

	public long getBatteryNextPhase(long length) {
		return mSharedPreferences.getLong(BATTERY_NEXT_PHASE, length);
	}

	public void putBatteryRemainLength(float length) {
		Editor editor = mSharedPreferences.edit();
		editor.putFloat(BATTERY_REMAIN_LENGTH, length);
		editor.commit();
	}

	public float getBatteryRemainLength(float length) {
		return mSharedPreferences.getFloat(BATTERY_REMAIN_LENGTH, length);
	}

	public void putAfterFullTimeLength(long length) {
		Editor editor = mSharedPreferences.edit();
		editor.putLong(AFTER_FULL_TIME_LENGTH, length);
		editor.commit();
	}

	public long getAfterFullTimeLength(long length) {
		return mSharedPreferences.getLong(AFTER_FULL_TIME_LENGTH, length);
	}

	public boolean isAutoStartup(boolean defaultVaule) {
		return mSharedPreferences.getBoolean(PREFERENCES_AUTO_STARTUP,
				defaultVaule);
	}

	public boolean isAutoUpdate(boolean defaultVaule) {
		return mSharedPreferences.getBoolean(PREFERENCES_AUTO_UPDATE,
				defaultVaule);
	}

	public boolean isShowBatteryIcon(boolean defaultVaule) {
		return mSharedPreferences.getBoolean(NOTIFICATIONBAR_SHOW_BATTERY_ICON,
				defaultVaule);
	}

	public void putShowBatteryIcon(boolean defaultVaule) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(NOTIFICATIONBAR_SHOW_BATTERY_ICON, defaultVaule);
		editor.commit();
	}

	public boolean isShowLowBatteryNotification(boolean defaultVaule) {
		return mSharedPreferences.getBoolean(LOW_BATTERY_NOTIFICATION,
				defaultVaule);
	}

	/**
	 * 设置是否低电量提醒
	 * 
	 * @param value
	 */
	public void putShowLowBatteryNotification(boolean value) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(LOW_BATTERY_NOTIFICATION, value);
		editor.commit();
	}

	/**
	 * 设置低电量提醒的值
	 * 
	 * @param value
	 */
	public void putLowBatteryNotificationValue(String value) {
		Editor editor = mSharedPreferences.edit();
		editor.putString(LOW_BATTERY_NOTIFICATION_VALUE, value);
		editor.commit();
	}

	/**
	 * 获取低电量提醒值
	 * 
	 * @param defaultValue
	 * @return
	 */
	public String getLowBatteryNotificationValue(String defaultValue) {
		return mSharedPreferences.getString(LOW_BATTERY_NOTIFICATION_VALUE,
				defaultValue);
	}

	public boolean isShowChargingDoneNotification(boolean defaultVaule) {
		return mSharedPreferences.getBoolean(CHANGING_DONE_NOTIFICATION,
				defaultVaule);
	}

	public void setChargingDoneNotification(boolean defaultVaule) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(CHANGING_DONE_NOTIFICATION, defaultVaule);
		editor.commit();
	}

	public boolean isShowChargingSoundNotification(boolean defaultVaule) {
		return mSharedPreferences.getBoolean(CHANGING_NOTIFICATION,
				defaultVaule);
	}

	public boolean isShowChargingLockScreen() {
		if (getSavedVersionCode() >= CHANGING_LOCKSCREEN_VERCODE) {
			return mSharedPreferences.getBoolean(CHANGING_LOCKSCREEN,
					CHANGING_LOCKSCREEN_DEFAULT_STATUS_FALSE);
		} else {
			return mSharedPreferences.getBoolean(CHANGING_LOCKSCREEN,
					CHANGING_LOCKSCREEN_DEFAULT_STATUS_TRUE);
		}
	}

	public void setShowChargingLockScreen(boolean value) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(CHANGING_LOCKSCREEN, value);
		editor.commit();
	}

	public boolean isShakeShake(boolean defaultValue) {
		return mSharedPreferences.getBoolean(PREFERENCES_SHAKE_SHAKE,
				defaultValue);
	}

	public void putShakeShakeOff(boolean value) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(PREFERENCES_SHAKE_SHAKE, value);
		editor.commit();
	}

	/**
	 * 获取摇一摇设置的值
	 * 
	 * @param defaultValue
	 * @return
	 */
	public String getShakeShakeConfigValue(String defaultValue) {
		return mSharedPreferences.getString(PREFERENCES_SHAKE_SHAKE_VALUE,
				defaultValue);
	}

	/**
	 * 设置摇一摇设置的值
	 * 
	 * @param value
	 */
	public void putShakeShakeConfigValue(String value) {
		Editor editor = mSharedPreferences.edit();
		editor.putString(PREFERENCES_SHAKE_SHAKE_VALUE, value);
		editor.commit();
	}

	/**
	 * 获取用户自定义模式列表
	 **/
	public String getUserMode() {
		return mSharedPreferences.getString(CUSTOM_USER_MODE_LIST, "");
	}

	public void putUserMode(String values) {
		Editor editor = mSharedPreferences.edit();
		editor.putString(CUSTOM_USER_MODE_LIST, values);
		editor.commit();
	}

	public int getSelectedIndex(int index) {
		return mSharedPreferences
				.getInt(CUSTOM_USER_MODE_SELECTED_INDEX, index);
	}

	public void putSelectedIndex(int index) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(CUSTOM_USER_MODE_SELECTED_INDEX, index);
		editor.commit();
	}

	public long getOptimizationInterval(long value) {
		return mSharedPreferences.getLong(OPTIMIZATION_INTERVAL, value);
	}

	public void putOptimizationInterval(long value) {
		Editor editor = mSharedPreferences.edit();
		editor.putLong(OPTIMIZATION_INTERVAL, value);
		editor.commit();
	}

	public int getMemCleanProcessCount(int defValue) {
		return mSharedPreferences.getInt(MEM_CLEAN_PROCESS_COUNT, defValue);
	}

	public void putMemCleanProcessCount(int cleanCount) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(MEM_CLEAN_PROCESS_COUNT, cleanCount);
		editor.commit();
	}

	public long getMemCleanTime(long defValue) {
		return mSharedPreferences.getLong(MEM_CLEAN_TIME, defValue);
	}

	public void putMemCleanTime(long optCount) {
		Editor editor = mSharedPreferences.edit();
		editor.putLong(MEM_CLEAN_TIME, optCount);
		editor.commit();
	}

	public boolean getLowModeSwitch(boolean flag) {
		return mSharedPreferences.getBoolean(LOW_MODE_SWITCH, flag);
	}

	public void putLowModeSwitch(boolean flag) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(LOW_MODE_SWITCH, flag);
		editor.commit();
	}

	public boolean getSleepModeSwitch(boolean flag) {
		return mSharedPreferences.getBoolean(SLEEP_MODE_SWITCH, flag);
	}

	public void putSleepModeSwitch(boolean flag) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(SLEEP_MODE_SWITCH, flag);
		editor.commit();
	}

	public boolean getPhoneLowModeSwitch(boolean flag) {
		return mSharedPreferences.getBoolean(PHONE_LOW_MODE_SWITCH, flag);
	}

	public void putPhoneLowModeSwitch(boolean flag) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(PHONE_LOW_MODE_SWITCH, flag);
		editor.commit();
	}

	public boolean getScreenTimeoutModeSwitch(boolean flag) {
		return mSharedPreferences.getBoolean(SCREEN_TIMEOUT_INTEL_MODE_SWITCH,
				flag);
	}

	public void putScreenTimeoutModeSwitch(boolean flag) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(SCREEN_TIMEOUT_INTEL_MODE_SWITCH, flag);
		editor.commit();
	}

	public long getScreenTimeoutStartTime() {
		return mSharedPreferences.getLong(SCREEN_TIMEOUT_INTEL_START_TIME, 0);
	}

	public void putScreenTimeoutStartTime(long modeValue) {
		Editor editor = mSharedPreferences.edit();
		editor.putLong(SCREEN_TIMEOUT_INTEL_START_TIME, modeValue);
		editor.commit();
	}

	public boolean getWifiIntelModeSwitch(boolean flag) {
		return mSharedPreferences.getBoolean(WIFI_INTEL_MODE_SWITCH, flag);
	}

	public void putWifiIntelModeSwitch(boolean flag) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(WIFI_INTEL_MODE_SWITCH, flag);
		editor.commit();
	}

	public boolean getBluetoothIntelModeSwitch(boolean flag) {
		return mSharedPreferences.getBoolean(BLUETOOTH_INTEL_MODE_SWITCH, flag);
	}

	public void putBluetoothIntelModeSwitch(boolean flag) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(BLUETOOTH_INTEL_MODE_SWITCH, flag);
		editor.commit();
	}

	public boolean getRootIntelModeSwitch(boolean flag) {
		return mSharedPreferences.getBoolean(ROOT_INTEL_MODE_SWITCH, flag);
	}

	public void putRootIntelModeSwitch(boolean flag) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(ROOT_INTEL_MODE_SWITCH, flag);
		editor.commit();
	}

	public boolean getRootReported(boolean flag) {
		return mSharedPreferences.getBoolean(ROOT_REPORTED, flag);
	}

	public void putRootReported(boolean flag) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(ROOT_REPORTED, flag);
		editor.commit();
	}

	public boolean getSetOnBoot(boolean flag) {
		return mSharedPreferences.getBoolean(SET_ON_BOOT, flag);
	}

	public void putSetOnBoot(boolean flag) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(SET_ON_BOOT, flag);
		editor.commit();
	}

	public int getCpuSelectMin() {
		return mSharedPreferences.getInt(CPU_SELECT_FREQ_MIN, -1);
	}

	public void putCpuSelectMin(int minfreq) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(CPU_SELECT_FREQ_MIN, minfreq);
		editor.commit();
	}

	public int getCpuSelectMax() {
		return mSharedPreferences.getInt(CPU_SELECT_FREQ_MAX, -1);
	}

	public void putCpuSelectMax(int maxfreq) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(CPU_SELECT_FREQ_MAX, maxfreq);
		editor.commit();
	}

	public String getCpuSelectGovernor() {
		return mSharedPreferences.getString(CPU_SELECT_GOVERNOR, "null");
	}

	public void putCpuSelectGovernor(String curGovernor) {
		Editor editor = mSharedPreferences.edit();
		editor.putString(CPU_SELECT_GOVERNOR, curGovernor);
		editor.commit();
	}

	public int getPreScalingMin() {
		return mSharedPreferences.getInt(CUR_SCALING_FREQ_MIN, -1);
	}

	public void putPreScalingMin(int scaling_min) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(CUR_SCALING_FREQ_MIN, scaling_min);
		editor.commit();
	}

	public int getPreScalingMax() {
		return mSharedPreferences.getInt(CUR_SCALING_FREQ_MAX, -1);
	}

	public void putPreScalingMax(int scaling_max) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(CUR_SCALING_FREQ_MAX, scaling_max);
		editor.commit();
	}

	public int getScreenMin() {
		return mSharedPreferences.getInt(CPU_SCREEN_FREQ_MIN, -1);
	}

	public void putScreenMin(int screen_min) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(CPU_SCREEN_FREQ_MIN, screen_min);
		editor.commit();
	}

	public int getScreenMax() {
		return mSharedPreferences.getInt(CPU_SCREEN_FREQ_MAX, -1);
	}

	public void putScreenMax(int screen_max) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(CPU_SCREEN_FREQ_MAX, screen_max);
		editor.commit();
	}

	public long getScreenStartTime() {
		return mSharedPreferences.getLong(CPU_SCREEN_START_TIME, 0);
	}

	public void putScreenStartTime(long starttime) {
		Editor editor = mSharedPreferences.edit();
		editor.putLong(CPU_SCREEN_START_TIME, starttime);
		editor.commit();
	}

	public long getScreenEndTime() {
		return mSharedPreferences.getLong(CPU_SCREEN_END_TIME, 0);
	}

	public void putScreenEndTime(long endtime) {
		Editor editor = mSharedPreferences.edit();
		editor.putLong(CPU_SCREEN_END_TIME, endtime);
		editor.commit();
	}

	public boolean getScreenTimeCalculated(boolean def) {
		return mSharedPreferences.getBoolean(SCREEN_TIME_CALCULATED, def);
	}

	public void putScreenTimeCalculated(boolean def) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(SCREEN_TIME_CALCULATED, def);
		editor.commit();
	}

	public int getLowModeLevel(int value) {
		return mSharedPreferences.getInt(LOW_MODE_LEVEL, value);
	}

	public void putLowModeLevel(int value) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(LOW_MODE_LEVEL, value);
		editor.commit();
	}

	public int getLowModeId(int value) {
		return mSharedPreferences.getInt(LOW_MODE_POSITION, value);
	}

	public void putLowModeId(int value) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(LOW_MODE_POSITION, value);
		editor.commit();
	}

	// public String getLowModeName(String defaultValue) {
	// return mSharedPreferences.getString(LOW_MODE_NAME, defaultValue);
	// }

	// public void putLowModeName(String modeValue) {
	// Editor editor = mSharedPreferences.edit();
	// editor.putString(LOW_MODE_NAME, modeValue);
	// editor.commit();
	// }

	// public String getTempLowModeName(String defaultValue) {
	// return mSharedPreferences.getString(TEMP_LOW_MODE_NAME, defaultValue);
	// }

	// public void putTempLowModeName(String modeValue) {
	// Editor editor = mSharedPreferences.edit();
	// editor.putString(TEMP_LOW_MODE_NAME, modeValue);
	// editor.commit();
	// }

	public int getTempLowModeId(int id) {
		return mSharedPreferences.getInt(TEMP_LOW_MODE_POSITION, id);
	}

	public void putTempLowModeId(int id) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(TEMP_LOW_MODE_POSITION, id);
		editor.commit();
	}

	public int getTempSleepPos(int pos) {
		return mSharedPreferences.getInt(TEMP_SLEEP_MODE_POSITION, pos);
	}

	public void putTempSleepPos(int pos) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(TEMP_SLEEP_MODE_POSITION, pos);
		editor.commit();
	}

	public String getTempSleepModeName(String defaultValue) {
		return mSharedPreferences.getString(TEMP_SLEEP_MODE_NAME, defaultValue);
	}

	public void putTempSleepModeName(String modeValue) {
		Editor editor = mSharedPreferences.edit();
		editor.putString(TEMP_SLEEP_MODE_NAME, modeValue);
		editor.commit();
	}

	public int getSleepModeStartTime() {
		return mSharedPreferences.getInt(SLEEP_MODE_START_TIME, 22 * 60);
	}

	public void putSleepModeStartTime(int nTime) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(SLEEP_MODE_START_TIME, nTime);
		editor.commit();
	}

	public int getSleepModeEndTime() {
		return mSharedPreferences.getInt(SLEEP_MODE_END_TIME, 7 * 60);
	}

	public void putSleepModeEndTime(int nTime) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(SLEEP_MODE_END_TIME, nTime);
		editor.commit();
	}

	public int getSleepModePosition(int value) {
		return mSharedPreferences.getInt(SLEEP_MODE_POSITION, value);
	}

	public void putSleepModePosition(int value) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(SLEEP_MODE_POSITION, value);
		editor.commit();
	}

	public String getSleepModeName(String defaultValue) {
		return mSharedPreferences.getString(SLEEP_MODE_NAME, defaultValue);
	}

	public void putSleepModeName(String modeValue) {
		Editor editor = mSharedPreferences.edit();
		editor.putString(SLEEP_MODE_NAME, modeValue);
		editor.commit();
	}

	public float getBatteryAvailableTime() {
		return mSharedPreferences.getFloat(BATTERY_AVAILABLE_TIME, 0);
	}

	public void putBatteryAvailableTime(float atime) {
		Editor editor = mSharedPreferences.edit();
		editor.putFloat(BATTERY_AVAILABLE_TIME, atime);
		editor.commit();
	}

	public boolean getPhoneSingalStateSwitch() {
		return mSharedPreferences.getBoolean(PHONE_SINGAL_STATE_SWITCH, false);
	}

	public void putPhoneSingalStateSwitch(boolean flag) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(PHONE_SINGAL_STATE_SWITCH, flag);
		editor.commit();
	}

	public long getBluetoothMonitorStartTime() {
		return mSharedPreferences.getLong(BLUETOOTH_MONITOR_START_TIME, 0);
	}

	public void putBluetoothMonitorStartTime(long modeValue) {
		Editor editor = mSharedPreferences.edit();
		editor.putLong(BLUETOOTH_MONITOR_START_TIME, modeValue);
		editor.commit();
	}

	public long getWifiMonitorStartTime() {
		return mSharedPreferences.getLong(WIFI_MONITOR_START_TIME, 0);
	}

	public void putWifiMonitorStartTime(long modeValue) {
		Editor editor = mSharedPreferences.edit();
		editor.putLong(WIFI_MONITOR_START_TIME, modeValue);
		editor.commit();
	}

	public void putMmMonitorStartTime(long modeValue) {
		Editor editor = mSharedPreferences.edit();
		editor.putLong(MM_MONITOR_START_TIME, modeValue);
		editor.commit();
	}

	public long getMmMonitorStartTime() {
		return mSharedPreferences.getLong(MM_MONITOR_START_TIME, 0);
	}

	public long getPhoneSingalHighStartTime() {
		return mSharedPreferences.getLong(PHONE_SINGAL_HIGH_START_TIME,
				System.currentTimeMillis());
	}

	public void putPhoneSingalHighStartTime(long modeValue) {
		Editor editor = mSharedPreferences.edit();
		editor.putLong(PHONE_SINGAL_HIGH_START_TIME, modeValue);
		editor.commit();
	}

	public long getPhoneSingalLowStartTime() {
		return mSharedPreferences.getLong(PHONE_SINGAL_LOW_START_TIME,
				System.currentTimeMillis());
	}

	public void putPhoneSingalLowStartTime(long modeValue) {
		Editor editor = mSharedPreferences.edit();
		editor.putLong(PHONE_SINGAL_LOW_START_TIME, modeValue);
		editor.commit();
	}

	public boolean isPhoneCalling() {
		return mSharedPreferences.getBoolean(CURRENT_PHONE_STATE, false);
	}

	public void putPhoneCalling(boolean flag) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(CURRENT_PHONE_STATE, flag);
		editor.commit();
	}

	public boolean isSwitchOffline() {
		return mSharedPreferences.getBoolean(SWITCH_OFF_LINE, false);
	}

	public void putSwitchOffline(boolean flag) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(SWITCH_OFF_LINE, flag);
		editor.commit();
	}

	public void putShowPlug(boolean flag) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(SHOW_PLUG_NOTIFY, flag);
		editor.commit();
	}

	public boolean getShowPlug() {
		return mSharedPreferences.getBoolean(SHOW_PLUG_NOTIFY, false);
	}

	public void removeMode(int pos) {
		Editor editor = mSharedPreferences.edit();
		editor.remove(SCREEN_BRIGHTNESS_MODE + pos);
		editor.remove(SCREEN_BRIGHTNESS + pos);
		editor.remove(SCREEN_OFF_TIMEOUT + pos);
		editor.remove(WIFI_SETTING + pos);
		editor.remove(BLUETOOTH_SETTING + pos);
		editor.remove(MASTER_SYNC_AUTO_MATICALLY + pos);
		editor.remove(VIBRATE_MODE + pos);
		editor.remove(FEED_BACK + pos);
		editor.commit();
	}

	public boolean getExitFlag(boolean defValue) {
		return mSharedPreferences.getBoolean(EXIT_FLAG, defValue);
	}

	public void putExitFlag(boolean value) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(EXIT_FLAG, value);
		editor.commit();
	}

	public boolean isShowWidgetTip() {
		return mSharedPreferences.getBoolean(Constant.Preferences.WIDGET_TIP,
				true);
	}

	public void setShowWidgetTip(boolean value) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(Constant.Preferences.WIDGET_TIP, value);
		editor.commit();
	}

	public boolean isShowScrBrightnessTip() {
		return mSharedPreferences.getBoolean(
				Constant.Preferences.SCR_SCROLL_BRIGHTNESS, true);
	}

	public void setShowScrBrightnessTip(boolean value) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(Constant.Preferences.SCR_SCROLL_BRIGHTNESS, value);
		editor.commit();
	}

	public void putMemClnExtTime(int value) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(Constant.Preferences.MEMCLN_EXT_TIME, value);
		editor.commit();
	}

	public int getMemClnExtTime(int defValue) {
		return mSharedPreferences.getInt(Constant.Preferences.MEMCLN_EXT_TIME,
				defValue);
	}

	public boolean getWeiboLogin(boolean defValue) {
		return mSharedPreferences.getBoolean(Constant.Weibo.LOGIN, defValue);
	}

	public void putWeiboLogin(boolean value) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(Constant.Weibo.LOGIN, value);
		editor.commit();
	}

	public void putWeiboToken(String value) {
		Editor editor = mSharedPreferences.edit();
		editor.putString(Constant.Weibo.TOKEN, value);
		editor.commit();
	}

	public String getWeiboToken(String defValue) {
		return mSharedPreferences.getString(Constant.Weibo.TOKEN, defValue);
	}

	public void putWeiboVerifier(String value) {
		Editor editor = mSharedPreferences.edit();
		editor.putString(Constant.Weibo.VERIFIER, value);
		editor.commit();
	}

	public String getWeiboVerifier(String defValue) {
		return mSharedPreferences.getString(Constant.Weibo.VERIFIER, defValue);
	}

	public void putWeiboExpiresIn(String value) {
		Editor editor = mSharedPreferences.edit();
		editor.putString(Constant.Weibo.EXPIRESIN, value);
		editor.commit();
	}

	public String getWeiboExpiresIn() {
		return mSharedPreferences.getString(Constant.Weibo.EXPIRESIN, "");
	}

	public void putWeiboScreenName(String value) {
		Editor editor = mSharedPreferences.edit();
		editor.putString(Constant.Weibo.SCREENAME, value);
		editor.commit();
	}

	public String getWeiboScreenName(String defValue) {
		return mSharedPreferences.getString(Constant.Weibo.SCREENAME, defValue);
	}

	public void putWeiboFocus(boolean value) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(Constant.Weibo.ISFOUCUS, value);
		editor.commit();
	}

	public boolean getWeiboFoucus(boolean defValue) {
		return mSharedPreferences.getBoolean(Constant.Weibo.ISFOUCUS, defValue);
	}

	public boolean getWeiboFoucusCheck(boolean defValue) {
		return mSharedPreferences.getBoolean(Constant.Weibo.ISFOUCUS_CHCKE,
				defValue);
	}

	public void putWeiboFocusCheck(boolean value) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(Constant.Weibo.ISFOUCUS_CHCKE, value);
		editor.commit();
	}

	public void putWeiboSecret(String value) {
		Editor editor = mSharedPreferences.edit();
		editor.putString(Constant.Weibo.SECRET, value);
		editor.commit();
	}

	public String getWeiboSecret(String defValue) {
		return mSharedPreferences.getString(Constant.Weibo.SECRET, defValue);
	}

	public boolean isGuideShow(boolean defValue, int versionCode) {
		boolean value = mSharedPreferences.getBoolean("isGuideShow", defValue);
		if (!value) {
			Editor editor = mSharedPreferences.edit();
			editor.putBoolean("isGuideShow", true);
			editor.commit();
			isGuideShowFunction(false, versionCode);
		}
		return value;
	}

	public boolean isGuideShowFunction(boolean defValue, int versionCode) {
		boolean value = mSharedPreferences.getBoolean("isGuideShowFunction_"
				+ versionCode, defValue);
		if (!value) {
			Editor editor = mSharedPreferences.edit();
			editor.putBoolean("isGuideShowFunction_" + versionCode, true);
			editor.commit();
		}
		return value;
	}

	public int getScreenWidth() {
		return mSharedPreferences.getInt(SCREEN_WIDTH, 0);
	}

	public void putScreenWidth(int width) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(SCREEN_WIDTH, width);
		editor.commit();
	}

	public int getScreenHeigth() {
		return mSharedPreferences.getInt(SCREEN_HEIGTH, 0);
	}

	public void putScreenHeigth(int height) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(SCREEN_HEIGTH, height);
		editor.commit();
	}

	public float getScreenDensity() {
		return mSharedPreferences.getFloat(SCREEN_DENSITY, 0.0f);
	}

	public void putScreenDensity(float density) {
		Editor editor = mSharedPreferences.edit();
		editor.putFloat(SCREEN_DENSITY, density);
		editor.commit();
	}

	public int getPluggedStatus() {
		return mSharedPreferences.getInt(PLUGGED_STATUS, 0);
	}

	public void putPluggedStatus(int plugged) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(PLUGGED_STATUS, plugged);
		editor.commit();
	}

	public boolean getShortCutInstalled() {
		return mSharedPreferences.getBoolean(SHORTCUTINSTALLED, false);
	}

	public void putShortCutInstalled() {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(SHORTCUTINSTALLED, true);
		editor.commit();
	}

	public boolean getBatteryShortCutInstalled() {
		return mSharedPreferences.getBoolean(BATTERY_SHORTCUT_NEW_INSTALLED,
				false);
	}

	public void putBatteryShortCutInstalled() {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(BATTERY_SHORTCUT_NEW_INSTALLED, true);
		editor.commit();
	}

	public boolean getBatteryOneKeyInstalled() {
		return mSharedPreferences.getBoolean(BATTERY_ONKEY_SHORTCUT_INSTALLED,
				false);
	}

	public void putBatteryOneKeyInstalled() {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(BATTERY_ONKEY_SHORTCUT_INSTALLED, true);
		editor.commit();
	}

	public boolean getBatteryShortCutUninstalled() {
		return mSharedPreferences.getBoolean(BATTERY_SHORTCUTINSTALLED, false);
	}

	public void putBatteryShortCutUnInstalled() {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(BATTERY_SHORTCUTINSTALLED, false);
		editor.commit();
	}

	public void putChargeEstimate(int value) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(ANALYSIS_CHARGE_ESTIMATE, value);
		editor.commit();
	}

	public int getChargeEstimate(int defValue) {
		return mSharedPreferences.getInt(ANALYSIS_CHARGE_ESTIMATE, defValue);
	}

	public int getStatusIconStyle() {
		return mSharedPreferences.getInt(STATUS_ICON_STYLE, 0);
	}

	public void putStatusIconStyle(int value) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(STATUS_ICON_STYLE, value);
		editor.commit();
	}

	public int getWidgetBGStyle() {
		return mSharedPreferences.getInt(WIDGET_BG_STYLE,
				Constant.WIDGET_STYLE_BLACK);
	}

	public void putWidgetBGStyle(int value) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(WIDGET_BG_STYLE, value);
		editor.commit();
	}

	/**
	 * 电池保养的每日基础分
	 * 
	 * @param value
	 */
	public void putScoreBase(float value) {
		value = value >= 5 ? 5 : value;
		Editor editor = mSharedPreferences.edit();
		editor.putFloat(SCORE_BASE, value);
		editor.commit();
	}

	public float getScoreBase(float defValue) {
		return mSharedPreferences.getFloat(SCORE_BASE, defValue);
	}

	/**
	 * 电池保养评分
	 * 
	 * @param value
	 */
	public void putScore(float value) {
		value = value >= 5 ? 5 : value;
		Editor editor = mSharedPreferences.edit();
		editor.putFloat(SCORE, value);
		editor.commit();
	}

	public float getScore(float defValue) {
		return mSharedPreferences.getFloat(SCORE, defValue);
	}

	/**
	 * 得到电池保养分数的初始化日期
	 * 
	 * @return
	 */
	public String getScoreDate(String defValue) {
		if ("null".equals(mSharedPreferences.getString(SCORE_DATE, "null"))) {
			// 初始化
			putScoreDate(defValue);
			return defValue;
		} else {
			return mSharedPreferences.getString(SCORE_DATE, defValue);
		}
	}

	/**
	 * 记录初始化日期--一天仅初始化一次
	 * 
	 * @param value
	 */
	public void putScoreDate(String value) {
		Editor editor = mSharedPreferences.edit();
		editor.putString(SCORE_DATE, value);
		editor.commit();
	}

	/**
	 * 得到电池保养的提示
	 * 
	 * @return
	 */
	public int getScoreTip(int defValue) {
		return mSharedPreferences.getInt(SCORE_TIP, defValue);
	}

	/**
	 * 记录初始化日期--一天仅初始化一次
	 * 
	 * @param value
	 */
	public void putScoreTip(int value) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(SCORE_TIP, value);
		editor.commit();
	}

	public int getScoreDays(int defValue) {
		return mSharedPreferences.getInt(SCORE_DAY, defValue);
	}

	/**
	 * 记录多少天没有使用电池医生充电了
	 * 
	 * @param value
	 */
	public void putScoreDays(int value) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(SCORE_DAY, value);
		editor.commit();
	}

	/**
	 * 得到/初始化 第一次运行日期
	 * 
	 * @return
	 */
	public String getFirstRunDate() {
		String date = mSharedPreferences.getString("FirstRunDate", null);
		if (TextUtils.isEmpty(date)) {
			date = DateUtil.getNowFormatDate("yyyy-MM-dd HH:mm:ss");
			putFirstRunDate(date);
			return date;
		}
		return date;
	}

	private void putFirstRunDate(String value) {
		Editor editor = mSharedPreferences.edit();
		editor.putString("FirstRunDate", value);
		editor.commit();
	}

	public boolean isMergeSleepSwOver() {
		boolean b = mSharedPreferences.getBoolean("isMergeSleepSwOver", true);
		if (b) {
			Editor editor = mSharedPreferences.edit();

			editor.putBoolean("isMergeSleepSwOver", false);
			editor.commit();
		}

		return b;
	}

	public void putClockRepeat(boolean flag) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean(CLOCK_REPEAT, flag);
		editor.commit();
	}

	public boolean getClockRepeat() {
		return mSharedPreferences.getBoolean(CLOCK_REPEAT, true);
	}

	public boolean isFileOpenWatcherOn() {
		return mSharedPreferences.getBoolean("app_cost_battery_monitor", true);
	}

	/** 屏保样式 */
	public int getScrStyle() {
		File lock = new File(Constant.KBD_SCR_LOCK);
		if (lock.exists())
			return Constant.SCR_STYLE_MOXIU;
		else
			return Constant.SCR_STYLE_COLORFUL;
	}

	public int putScrStyle(int value) {
		File lock = new File(Constant.KBD_SCR_LOCK);
		if (Constant.SCR_STYLE_MOXIU == value)
			try {
				lock.createNewFile();
				return value;
			} catch (IOException ex) {
			}
		else
			lock.delete();
		return Constant.SCR_STYLE_COLORFUL;
	}

	/** 获取七彩屏保颜色 */
	public int getScrColorfulColor(int value) {
		return mSharedPreferences.getInt(SCR_COLORFUL_COLOR, value);
	}

	/** 设置七彩屏保颜色 */
	public void putScrColorfulColor(int value) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(SCR_COLORFUL_COLOR, value);
		editor.commit();
	}

	/** 获取七彩屏保亮度 */
	public int getScrColorfulBrightness(int value) {
		return mSharedPreferences.getInt(SCR_COLORFUL_BRIGHTNESS, value);
	}

	/** 设置七彩屏保亮度 */
	public void putScrColorfulBrightness(int value) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(SCR_COLORFUL_BRIGHTNESS, value);
		editor.commit();
	}

	public int getLowLevelChangeId() {
		return mSharedPreferences.getInt(LOW_LEVEL_CHANGE_ID,
				Constant.NO_MODE_POSITION);
	}

	public void putLowLevelChangeId(int count) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt(LOW_LEVEL_CHANGE_ID, count);
		editor.commit();
	}

	/**
	 * 添加存根信息
	 * 
	 * @param pkName
	 *            包名，做为key
	 * @param type
	 *            安装途径， value
	 */
	public void putReportData(String pkName, String type) {
		if (pkName != null) {
			Editor editor = mSharedPreferences2Apps.edit();
			editor.putString(pkName, type);
			editor.commit();
		}
	}

	public void removeReportedData(String pkgName) {
		Editor editor = mSharedPreferences2Apps.edit();
		editor.remove(pkgName);
		editor.commit();
	}

	public String getAppPkgName(String pkName) {
		return mSharedPreferences2Apps.getString(pkName, Constant.STR_BLANK);
	}

	public boolean getOneKeyTipShow(boolean defValue) {
		boolean value = mSharedPreferences.getBoolean("onekey_tip_show",
				defValue);
		if (value) {
			Editor editor = mSharedPreferences.edit();
			editor.putBoolean("onekey_tip_show", !value);
			editor.commit();
		}
		return value;
	}

	/**
	 * 
	 * @param c
	 * @param key1
	 * @param key2
	 * @param etag
	 */

	public static void putEtag(Context c, String key1, String key2, String etag) {
		SharedPreferences sp = c.getSharedPreferences(PREFERENCE_HTTP_ETAG,
				Context.MODE_PRIVATE);
		Editor editor = sp.edit();
		editor.putString(key1 + "_" + key2, etag);
		editor.commit();
	}

	public static String getEtag(Context c, String key1, String key2) {
		SharedPreferences sp = c.getSharedPreferences(PREFERENCE_HTTP_ETAG,
				Context.MODE_PRIVATE);
		return sp.getString(key1 + "_" + key2, "");
	}

	public void putNewAppsId(Context c, String ids) {
		SharedPreferences sp = c.getSharedPreferences(PREFERENCE_NEW_APPS,
				Context.MODE_PRIVATE);
		Editor editor = sp.edit();
		editor.putString(Constant.PREFERENCE_IDS, ids);
		editor.commit();
	}

	public String getNewAppsId(Context c) {
		SharedPreferences sp = c.getSharedPreferences(PREFERENCE_NEW_APPS,
				Context.MODE_PRIVATE);
		return sp.getString(Constant.PREFERENCE_IDS, "");
	}

	public void putIsOpenBoutique(Context c, boolean isOpen) {
		SharedPreferences sp = c.getSharedPreferences(PREFERENCE_NEW_APPS,
				Context.MODE_PRIVATE);
		Editor editor = sp.edit();
		editor.putBoolean(Constant.PREFERENCE_IS_OPEN, isOpen);
		editor.commit();
	}

	public boolean getIsOpenBoutique(Context c) {
		SharedPreferences sp = c.getSharedPreferences(PREFERENCE_NEW_APPS,
				Context.MODE_PRIVATE);
		return sp.getBoolean(Constant.PREFERENCE_IS_OPEN, false);
	}

	public void putNewAppsCount(Context c, int count) {
		SharedPreferences sp = c.getSharedPreferences(PREFERENCE_NEW_APPS,
				Context.MODE_PRIVATE);
		Editor editor = sp.edit();
		editor.putInt(Constant.PREFERENCE_COUNT, count);
		editor.commit();
	}

	public int getNewAppsCount(Context c) {
		SharedPreferences sp = c.getSharedPreferences(PREFERENCE_NEW_APPS,
				Context.MODE_PRIVATE);
		return sp.getInt(Constant.PREFERENCE_COUNT, 0);
	}

	public long getShowGPRSTipTime(Context c) {
		SharedPreferences sp = c.getSharedPreferences(PREFERENCE_NEW_APPS,
				Context.MODE_PRIVATE);
		return sp.getLong(SHOW_GPRS_TIPS_TIME, 0);
	}

	public void putShowGPRSTipTime(Context c, long time) {
		SharedPreferences sp = c.getSharedPreferences(PREFERENCE_NEW_APPS,
				Context.MODE_PRIVATE);
		Editor editor = sp.edit();
		editor.putLong(SHOW_GPRS_TIPS_TIME, time);
		editor.commit();
	}
}
